<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible"content="IE=8"><!--以IE8模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=7"><!--以IE7模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=9; IE=8; IE=7; IE=EDGE">
	<title>用户操作</title>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/long_add.css" >
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.css"/>
	<script type="text/javascript" src="__PUBLIC__/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.easydrag.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ajax.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
</head>
<body>
	<style>
		#check 
		{
			width:100px;
			height:30px;
			line-height: 20px;
			outline:medium;
			align:center;
			border:1px solid #eaeaea;
			border-radius:4px;
			background:#f7f7f7;
			margin-right:6px;
		}
	</style>

	<div class="contentPage">
		<form action="../../customer/customer/reference_check_Submit" method="post" name="materalcheckForm">
			<input type="hidden" name="ref_id" value=<?php echo $data_reference['ref_id']; ?> >
			<table class="addForm">
				<tr>
					<th><span>*</span>客户姓名：</th>
					<td><input type="text"  name="custname" value=<?php echo $data_custInfo['cust_name']; ?> readonly="readonly"></td>
				</tr>

				<tr>
					<th>客户ID：</th>
					<td><input name = "custId" type="text" value=<?php echo $data_custInfo['cust_id']; ?> readonly="readonly"></td>
				</tr>

				<tr>
					<th><span>*</span>材料类型：</th>
					<td>
						<input type="text"  value=<?php echo $data_refertype['refertype_name']; ?> readonly="readonly">
					</td>
				</tr>

				<tr>
					<th><span>*</span>上传资料：</th>
					<td>
						<?php
							$path = 'http://' . $_SERVER['HTTP_HOST'] . '/Public/Upload/UploadAudit/';
							foreach ($array_file as $key => $value) 
							{
								echo "<input type='button' value = '下载' onclick='down(\"".$path.$value['ref_annex']."\")''>";
								echo "<input type='button' value = '预览' onclick='preview(\"".$path.$value['ref_annex']."\")''>";
							}
						?>
					</td>
				</tr>

				<tr>
					<th>审核状态：</th>
					<td>
						<select  id="check" name="checkstatus">
							<option value="1">通过</option>
							<option value="2">不通过</option>
						</select>
					</td>
				</tr>

				<tr>
					<th>审核分数：</th>
					<td>
						<input type="text" name="point" id="point" value="<?php echo $data_reference['ref_point']; ?>">
						<input type="hidden" id="score" value="<?php echo $data_refertype['refertype_score']; ?>"/>
						<?php
							if ($data_refertype['refertype_score'] == '0') 
							{
								echo '<span style="color:red"> 身份证无需打分</span>';
							}
							else
							{
								echo '<span style="color:red"> 审核分数最高为:<span style="color:red">'.$data_refertype['refertype_score'].'</span>分</span>';
							}
						?>
					</td>
				</tr>

				<?php
					if ($data_refertype['refertype_id'] == '6') 
					{
				?>
				<tr>
					<th>选择期限限制：</th>
					<td>
						<select  id="period" name="period">
							<option value="1">24</option>
							<option value="2">18,24</option>
							<option value="3">12,18,24</option>
							<option value="4">9,12,18,24</option>
							<option value="5">6,9,12,18,24</option>
						</select>
					</td>
				</tr>
				<script>$("#period option[value='<?php echo $data_reference['ref_explain'] ?>'").attr("selected","selected");</script>
				<?php
					}
				?>
				
				<tr>
					<td colspan="2" class="addButton">
						<input type="button" value="保存"  class="save" onclick="submitForm();">
						<input type="button" value="刷新"  class="clear" onclick="window.location.reload();">
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>

<script>
	function submitForm() 
	{
		var score = $("#score").val();
		var point = $("#point").val();
		if(score != 0) 
		{
			if((point-score) > 0) 
			{
				jAlert('审核分数大于最高分！','错误提示',null);
				return;
			}
		}
		document.materalcheckForm.submit();
	}

	function preview(url) 
	{
		window.open(url);
	}

	function down(a) 
	{
		Downer(a);
	}

	var Downer = (function(files) {
		var h5Down = !/Trident|MSIE/.test(navigator.userAgent);
		/**
		 * 在支持 download 属性的情况下使用该方法进行单个文件下载
		 * @param  {String} fileName
		 * @param  {String|FileObject} contentOrPath
		 * @return {Null}
		 */
		function downloadFile(fileName, contentOrPath) 
		{
			var aLink = document.createElement("a"),
			evt = document.createEvent("HTMLEvents"),
			isData = contentOrPath.slice(0, 5) === "data:",
			isPath = contentOrPath.lastIndexOf(".") > -1;

			// 初始化点击事件
			evt.initEvent("click");

			// 添加文件下载名
			aLink.download = fileName;

			// 如果是 path 或者 dataURL 直接赋值
			// 如果是 file 或者其他内容，使用 Blob 转换
			aLink.href = isPath || isData ? contentOrPath : URL.createObjectURL(new Blob([contentOrPath]));
			aLink.dispatchEvent(evt);
		}

		/**
		 * [IEdownloadFile description]
		 * @param  {String} fileName
		 * @param  {String|FileObject} contentOrPath
		 */
		function IEdownloadFile(fileName, contentOrPath, bool) 
		{
			var isImg = contentOrPath.slice(0, 10) === "data:image",
			ifr = document.createElement('iframe');

			ifr.style.display = 'none';
			ifr.src = contentOrPath;

			document.body.appendChild(ifr);

			// dataURL 的情况
			isImg && ifr.contentWindow.document.write("<img src='" + contentOrPath + "' />");

			// 保存页面 -> 保存文件
			// alert(ifr.contentWindow.document.body.innerHTML)
			if(bool) 
			{
				ifr.contentWindow.document.execCommand('SaveAs', false, fileName);
				document.body.removeChild(ifr);
			}
			else
			{
				setTimeout(function(){
					ifr.contentWindow.document.execCommand('SaveAs', false, fileName);
					document.body.removeChild(ifr);
				}, 0);
			}
		}

		/**
		 * [parseURL description]
		 * @param  {String} str [description]
		 * @return {String}     [description]
		 */
		function parseURL(str) 
		{
			return str.lastIndexOf("/") > -1 ? str.slice(str.lastIndexOf("/") + 1) : str;
		}

		return function(files) 
		{
			// 选择下载函数
			var downer = h5Down ? downloadFile : IEdownloadFile;

			// 判断类型，处理下载文件名
			if(files instanceof Array) 
			{
				for(var i = 0, l = files.length; i < l ; i++) 
				{
					// bug 处理
					downer(parseURL(files[i]), files[i], true);
				}
			}
			else if(typeof files === "string") 
			{
				downer(parseURL(files), files);
			}
			else
			{
				// 对象
				for(var file in files) downer(file, files[file]);
			}
		}

	})();
</script>
</html>